package com.shengqiang.cloud.ups.controller;

import com.shengqiang.cloud.ups.common.model.JsonResult;
import com.shengqiang.cloud.ups.dao.modal.UpmsPermission;
import com.shengqiang.cloud.ups.service.UpmsResourceWebService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Administrator on 2017/12/31.
 * 资源管理
 */
@Controller
@RequestMapping(value = "sysResource")
public class UpmsResourceController {

    @Autowired
    private UpmsResourceWebService service;

    @RequestMapping(value = "toResource")
    public String toResource(){
        return "/systemSetting/menuResource";
    }

    @RequiresPermissions(value = "upms:users:department:list")
    @ResponseBody
    @RequestMapping(value = "selectResources",method = {RequestMethod.POST,RequestMethod.GET})
    public JsonResult<List<UpmsPermission>> selectResources(int menuId){
        return service.selectResources(menuId);
    }

    @RequiresPermissions(value = "upms:users:department:add")
    @ResponseBody
    @RequestMapping(value = "addSysResource",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult addSysResource(UpmsPermission upmsPermission){
        return service.addSysResource(upmsPermission);
    }

    @RequiresPermissions(value = "upms:users:department:edit")
    @ResponseBody
    @RequestMapping(value = "updateSysResource",method = {RequestMethod.POST,RequestMethod.GET})
    public JsonResult updateSysResource(UpmsPermission upmsPermission){
        return service.updateResource(upmsPermission);
    }

    @RequiresPermissions(value = "upms:users:department:delete")
    @ResponseBody
    @RequestMapping(value = "deleteSysResource",method = {RequestMethod.GET,RequestMethod.POST})
    public JsonResult deleteSysResource(int id){
        return service.deleteSysResource(id);
    }
}
